// ignore_for_file: prefer_const_constructors, use_key_in_widget_constructors, prefer_const_constructors_in_immutables, non_constant_identifier_names

import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety_flutter3/flutter_swiper_null_safety_flutter3.dart';
import '../../../models/home_models.dart';

class ImageSwiperWidget extends StatelessWidget {
  ImageSwiperWidget({
    this.imageBanners,
    this.height,
    this.Radius = 4.0,
  });

  ///轮播图数据
  final List<ImageBannersModel>? imageBanners;

  ///高度
  final double? height;

  ///圆角
  final double? Radius;

  @override
  Widget build(BuildContext context) {
    return imageBanners != null
        ? Container(
            //高度设置140
            height: height,
            // 切割圆角
            decoration:
                BoxDecoration(borderRadius: BorderRadius.circular(Radius!)),
            clipBehavior: Clip.antiAlias,
            child: Swiper(
              //自动轮播
              autoplay: true,
              itemBuilder: (BuildContext context, int index) {
                ImageBannersModel imageBannersModel = imageBanners![index];
                return Image.network(
                  imageBannersModel.imgUrl!,
                  //图片填充
                  fit: BoxFit.cover,
                );
              },
              itemCount: imageBanners!.length,
              //指示器
              pagination: SwiperPagination(),
            ),
          )
        : Container(
            height: height,
            decoration: BoxDecoration(
                color: Color(0xFFEBEBEB),
                borderRadius: BorderRadius.circular(Radius!)),
            alignment: Alignment.center,
            clipBehavior: Clip.antiAlias,
            child: Image.asset('assets/placeholder.png'),
          );
  }
}
